<?php
// +----------------------------------------------------------------------
// | sfadmin - Suifeng Administration
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2020 http://suifeng.tech All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: suifeng <1787585212@qq.com>
// +----------------------------------------------------------------------

namespace suifeng\builder\table\column;

use suifeng\helper\HtmlHelper;

class Status extends Text
{
    /**
     * 已知的状态列表。
     */
    public $status_list = array(
        1   => array('有效', 'label label-success'),
        0   => array('无效', 'label label-danger'),
        -1  => array('删除', 'label label-default'),
    );

    /**
     * 获取单元格内容。
     *
     * @param unknown $row
     * @return unknown|string
     */
    protected function _fetch_cell_content($row)
    {
        $value = $this->_get_cell_value($row);

        if (array_key_exists($value, $this->status_list)) {
            return HtmlHelper::render_tag('span',
                array('class' => $this->status_list[$value][1]),
                $this->status_list[$value][0]);
        } else {
            return $value;
        }
    }
}
